function ttArticleSubmit(data = ''){
	let postUrl = 'http://mp.toutiao.com/core/article/edit_article_post/?source=mp&type=article';
	result = '';
	$.ajax({
		url:postUrl,
		type:"post",
		async:false,
	    data:data,
		success:function(data){
			if(data.code == 0){
				result = true;
			}else{
				result = data.message;
			}
		},
		error:function(){
			layer.msg('头条文章抛送异常');
		}
	})
	return result;
}

function ttArticleArrange(data = ''){
	time_str = getNowFormatDate();
	let title = data.title;
	let content = `<p><br></p>`;
	for(item of data.items){
		if(item.type == 1){
			content = content+
			`<p>${item.content}</p><p><br></p>`;
	
		}
		if(item.type == 2){
			let imageObj = ttImageUpload(item.content);
			if(!imageObj){
				layer.msg('上传出错');
				return false;
			}
			content = content+
			`<div class="pgc-img"><img class="" src="${imageObj.url}" data-ic="false" data-ic-uri="" data-height="${imageObj.height}" data-width="${imageObj.height}" data-story_id="" data-image_ids="[]" image_type="${imageObj.image_type}" web_uri="${imageObj.origin_web_uri}" img_width="${imageObj.width}" img_height="${imageObj.height}"><p class="pgc-img-caption"></p></div>`;
		}
		
	}
	
	data = {
		article_type:0,
		title:title,
		content:content,
		article_ad_type:3,
		timer_time: time_str,
		save:1
	};
	return data;
}

function ttArticle(){
	let token = getCurrentToken();
	let postUrl = 'https://cutezz.cn/admin/article/item?token='+token+'&platform=头条';
	result = '';
	$.ajax({
		url:postUrl,
		type:"get",
		async:false,
		success:function(data){
			if(data.code == 200){
				if(data.result){
					result = data.result;
				}
				
			}
			console.log(data);
		},
		error:function(){
			layer.msg('头条文章获取异常');
		}
	})
	return result;
}

function ttImageUpload(imageUrl = ''){
	let url = 'http://mp.toutiao.com/tools/catch_picture/';
	result = '';
	if(imageUrl.indexOf('http') == -1){
		imageUrl = 'https:'+imageUrl;
	}
	data = {
		upfile:imageUrl,
		version:2
	};
	$.ajax({
		url:url,
		type:"post",
		async:false,
		data:data,
		success:function(data){
			if(data.hasOwnProperty('images')){
				images = data.images;
				if(images.length > 0){
					result = {};
					result = images[0]
				}
			}
			
		},
		error:function(){
			layer.msg('图片上传异常');
		}
	})
	return result;
}

//状态回写
function ttStatusWrite(article_id = ''){
	token = getCurrentToken();
	let url = 'https://cutezz.cn/admin/article/status';
	result = '';
	data = {
		platform:'头条',
		article_id:article_id,
		token:token,
	};
	$.ajax({
		url:url,
		type:"post",
		async:false,
	    data:data,
		success:function(data){
			if(data.code == 200){
				result = true;
			}
			
		},
		error:function(){
			layer.msg('头条状态回写异常');
		}
	})
	return result;
}
